const path = require('path')
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const distPath = path.resolve(__dirname, "../dist")
module.exports = {
    //  入口
    entry: "./src/main.js",
    // 出口
    output: {
        path: distPath,
        filename: "./js/app.bundle.js",
        clean: true,
        //静态资源根目录
        publicPath:"/"
    },
    // 生产模式
    mode: "production",
    // 压缩跟源码位置映射，方便找错
    devtool: "source-map",
    plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, '../public/index.html'),
            filename: "index.html",
            // script文件引入的位置
            inject: "body"
        }),
        new CopyPlugin({
            patterns: [
                {
                    from: path.resolve(__dirname, '../public'),
                    to: distPath,
                    globOptions: {
                        ignore: ["**/index.html*"],
                      },
                },
            ],
        }),
    ],
    module: {
        rules: [
          {
            test: /\.ejs$/,
            loader: 'ejs-loader',
            options: {
                // data 是咱们ejs文件中 能够接收到数据的桥梁
              variable: 'data'
            }
          },
          {
            test:/\.less$/,
            use:['style-loader','css-loader','less-loader']
          }
        ]
      },
    //   文件过大提示时可以用该方法取消提示
      performance: {
        hints: false,
      },

      resolve:{
        // 对后缀的省略配置
        extensions:['.js','.ejs','.less'],
        // 对文件名的配置
        alias:{
            $v:path.resolve(__dirname,'../src/views'),
            $com:path.resolve(__dirname,'../src/components'),
            $con:path.resolve(__dirname,'../src/controllers/'),
            $a:path.resolve(__dirname,'../src/api')
            
        },
        
      }
}